package com.brisk.web.controller.applet;

import com.ruoyi.applet.domain.AppletExamTopic;
import com.ruoyi.applet.service.IAppletExamTopicService;
import com.brisk.common.core.controller.BaseController;
import com.brisk.common.core.domain.AjaxResult;
import com.brisk.common.core.page.TableDataInfo;
import com.brisk.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * topicController
 *
 * @author PengFei Deng
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/applet/topic")
public class AppletExamTopicController extends BaseController {
    @Autowired
    private IAppletExamTopicService appletExamTopicService;

    /**
     * 查询topic列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppletExamTopic appletExamTopic) {
        startPage();
        List<AppletExamTopic> list = appletExamTopicService.selectAppletExamTopicList(appletExamTopic);
        return getDataTable(list);
    }

    /**
     * 导出topic列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppletExamTopic appletExamTopic) {
        List<AppletExamTopic> list = appletExamTopicService.selectAppletExamTopicList(appletExamTopic);
        ExcelUtil<AppletExamTopic> util = new ExcelUtil<AppletExamTopic>(AppletExamTopic.class);
        util.exportExcel(response, list, "topic数据");
    }

    /**
     * 获取topic详细信息
     */
    @GetMapping(value = "/{topicId}")
    public AjaxResult getInfo(@PathVariable("topicId") Long topicId) {
        return AjaxResult.success(appletExamTopicService.selectAppletExamTopicByTopicId(topicId));
    }

    /**
     * 新增topic
     */
    @PostMapping
    public AjaxResult add(@RequestBody AppletExamTopic appletExamTopic) {
        return toAjax(appletExamTopicService.insertAppletExamTopic(appletExamTopic));
    }

    /**
     * 修改topic
     */
    @PutMapping
    public AjaxResult edit(@RequestBody AppletExamTopic appletExamTopic) {
        return toAjax(appletExamTopicService.updateAppletExamTopic(appletExamTopic));
    }

    /**
     * 删除topic
     */
    @DeleteMapping("/{topicIds}")
    public AjaxResult remove(@PathVariable Long[] topicIds) {
        return toAjax(appletExamTopicService.deleteAppletExamTopicByTopicIds(topicIds));
    }
}
